package com.pks.datacenter.service.api;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.pks.datacenter.config.RedisKeyConfig;
import com.pks.datacenter.entity.api.ApiField;
import com.pks.datacenter.handler.RedisHandler;
import com.pks.datacenter.mapper.api.ApiFieldMapper;
import com.pks.util.SUtilQbuilder;
import com.pks.web.mybatis.service.BasicServiceImpl;

@Component("apiFieldService")
public class ApiFieldServiceImpl extends BasicServiceImpl<ApiField, Long, ApiFieldMapper> implements ApiFieldService {

	@Autowired
	private ApiFieldMapper apiFieldMapper;
	@Resource
	private RedisHandler redisHandler;

	@Override
	protected ApiFieldMapper getMapper() {
		return apiFieldMapper;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ApiField> findByApiId(Long apiId) {
		List<ApiField> list = new ArrayList<ApiField>();
		if (apiId != null) {
			Object obj = redisHandler.get(RedisKeyConfig.KEY_LIST_APIFIELDS_PREFIX + apiId);
			if (obj != null) {
				list = (List<ApiField>) obj;
			} else {
				list = apiFieldMapper.find(SUtilQbuilder.initQbuilder("apiId", apiId), null, null, null);
				redisHandler.set(RedisKeyConfig.KEY_LIST_APIFIELDS_PREFIX + apiId, list , RedisKeyConfig.CACHE_TIME);
			}
		}
		return list;
	}
	
	
	
}
